package cn.tedu.egmvc1.controller;

import cn.tedu.egmvc1.mapper.EmpMapper;
import cn.tedu.egmvc1.pojo.entity.Emp;
import cn.tedu.egmvc1.pojo.tdo.EmpInsert;
import cn.tedu.egmvc1.pojo.vo.EmpListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class EmpController {
    @Autowired
    private EmpMapper empMapper;


    @RequestMapping("/emps/insert")
    @ResponseBody
    public String insert(EmpInsert empInsert){
        Emp emp = new Emp();
        BeanUtils.copyProperties(empInsert,emp);
        empMapper.insertEmp(emp);
        return "添加成功";
    }


    @RequestMapping("/emps/select")
    @ResponseBody
    public List<EmpListVO> empListVO(){
        return empMapper.selectEmpListVO();
    }


    @RequestMapping("/emps/update")
    @ResponseBody
    public String update(Emp emp){
        Emp emp1 = new Emp();
        BeanUtils.copyProperties(emp,emp1);
        empMapper.updateEmp(emp1);
        return "修改成功";
    }


    @RequestMapping("/emps/delete")
    @ResponseBody
    public String delete(int id){
        empMapper.deleteEmp(id);
        return "删除成功";
    }

}
